package com.zhaoyizhe.demo.controller;

import ch.qos.logback.core.util.StringUtil;
import com.zhaoyizhe.demo.mapper.MessageInfoXMLMapper;
import com.zhaoyizhe.demo.model.MessageInfo;
import com.zhaoyizhe.demo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageController {

    @Autowired
    private MessageService messageService;

    @RequestMapping(value = "/getMsg")
    public Boolean getMsg(@RequestBody MessageInfo messageInfo){


        if (StringUtil.isNullOrEmpty(messageInfo.getFrom()) || StringUtil.isNullOrEmpty(messageInfo.getTo())
            || StringUtil.isNullOrEmpty(messageInfo.getMessage())){
            return false;
        }
        messageService.insertInfo(messageInfo);
        //list.add(messageInfo);
        System.out.println("信息存储成功");
        return true;
    }

    @RequestMapping("/showMsg")
    public List<MessageInfo> showMsg(){
        return messageService.queryInfo();
    }

}
